﻿@{
    ViewData["Title"] = "Index";
    Layout = "~/Areas/Console/Views/Shared/_Layout.cshtml";
}
@section head{
    <style type="text/css">
        .layui-table-cell {
            height: 52px;
            line-height: 52px;
        }

        .layui-layer-content {
            overflow: hidden !important;
        }

        .qrcode {
            width: 50px;
            height: 50px;
            display: inline-block;
            margin-right: 20px;
            vertical-align: middle;
        }

        .copy {
            vertical-align: middle;
            display: inline-block;
        }
    </style>
    <script type="text/javascript">
        var table;
        layui.config({
            base: '../../layuiadmin/modules/' //静态资源所在路径
        }).extend({
            treetable: 'treetable-lay/treetable'
            , qrcode: 'qrcode/qrcode' //主入口模块
        }).use(['table', 'form', 'treetable', 'qrcode'], function () {
            var $ = layui.$
                , form = layui.form
                , admin = layui.admin
                , table = layui.table

            // 渲染表格
            table.render({
                elem: '#table-datalist'
                , url: '/Console/PersonInfo/GetListJson'
                , limit: 20
                , title: '身份信息表'
                , toolbar: '#table-datalist-toolbar'
                , cols: [[
                    { field: 'id', title: '编号', hide: true }
                    , { field: 'name', title: '部门受案号' }
                    , { field: 'personname', title: '姓名/单位名称' }
                    , { field: 'idcard', title: '证件号码' }
                    //, { field: 'type', title: '类型', width: 150 }
                    , { field: 'addtime', title: '添加时间' }
                    , { field: 'updatetime', title: '最后更新时间' }
                    , { fixed: 'right', title: '操作', width: 80, toolbar: '#table-datalist-bar' }
                ]]
                , page: { layout: ['prev', 'page', 'next', 'refresh'] }
            });

            /* 监听提交 */
            form.on('submit(search)', function (data) {
                var params = {};
                params["name"] = $("#name").val();
                params["personname"] = $("#personname").val();
                params["idcard"] = $("#idcard").val();
                table.reload('table-datalist', {
                    where: params,
                    page: { curr: 1, layout: ['prev', 'page', 'next', 'refresh'] }
                });
                return false;
            });

            //重置
            form.on('submit(reset)', function (data) {
                $('#name').val('')
                $('#personname').val('')
                $('#idcard').val('')
                form.render()
                table.reload('table-datalist', {
                    where: null,
                    page: { curr: 1, layout: ['prev', 'page', 'next', 'refresh'] }
                });
                return false;
            });

            //监听行工具事件
            table.on('tool(table-datalist)', function (obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    layer.confirm('确定要删除此数据吗？', function (index) {
                        $.ajax({
                            type: "POST",
                            url: "/Console/PersonInfo/Delete",
                            data: { id: data.id }, // 你的formid
                            async: true,
                            error: function (request) {
                                alert("请求超时");
                            },
                            beforeSend: function (xhr) {
                                layui.layer.load();
                            },
                            success: function (data) {
                                var item = eval(data);
                                if (item.code == 0) {
                                    layer.msg("删除成功", { icon: 1, time: 1000 }, function () {
                                        table.reload("table-datalist");
                                    });
                                } else if (item.code == 1) {
                                    layer.msg(item.msg, { icon: 2 });
                                } else {
                                    layer.msg("删除失败", { icon: 0 });
                                }
                                layer.closeAll('loading');
                            }
                        });
                    });
                }
            });

            //清空数据
            form.on('submit(delAll)', function (data) {
                layer.confirm('确定要删除此数据吗？', function (index) {
                    $.ajax({
                        type: "POST",
                        url: "/Console/PersonInfo/DeleteAll",
                        data: { id: data.id }, // 你的formid
                        async: true,
                        error: function (request) {
                            alert("请求超时");
                        },
                        beforeSend: function (xhr) {
                            layui.layer.load();
                        },
                        success: function (data) {
                            var item = eval(data);
                            if (item.code == 0) {
                                layer.msg("删除成功", { icon: 1, time: 1000 }, function () {
                                    table.reload("table-datalist");
                                });
                            } else if (item.code == 1) {
                                layer.msg(item.msg, { icon: 2 });
                            } else {
                                layer.msg("删除失败", { icon: 0 });
                            }
                            layer.closeAll('loading');
                        }
                    });
                });
            });
        });
    </script>
}
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    @*<div class="layui-card-header">条件查询</div>*@
                    <div class="layui-card-body">
                        <form class="layui-form layui-form-pane" action="" lay-filter="component-form-group">
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width:120px">部门受案号</label>
                                    <div class="layui-input-inline">
                                        <input type="text" id="name" name="name" value="" maxlength="25" placeholder="请填写需要查询的关键字" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width:120px">姓名/单位名称</label>
                                    <div class="layui-input-inline">
                                        <input type="text" id="personname" name="personname" value="" maxlength="25" placeholder="请填写需要查询的关键字" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width:120px">证件号码</label>
                                    <div class="layui-input-inline">
                                        <input type="text" id="idcard" name="idcard" value="" maxlength="25" placeholder="请填写需要查询的关键字" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <button class="layui-btn  layui-btn-normal search-btn" lay-submit lay-filter="search" data-type="search"><i class="layui-icon layui-icon-search"></i>搜索</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
                <div class="layui-card">
                    <div class="layui-card-body">
                        <table class="layui-hide" id="table-datalist" lay-filter="table-datalist"></table>
                        <script type="text/html" id="table-datalist-toolbar">
                            <div class="layui-btn-container">
                                  <button class="layui-btn  layui-btn-danger search-btn" lay-submit lay-filter="delAll">清空数据</button>
                             </div>
                        </script>
                        <script type="text/html" id="table-datalist-bar">
                            <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</button>
                        </script>
                    </div>
                </div>
            </div>
        </div>
    </div>